package com.d0319;

public class EggTest {
    volatile boolean hasEggs=false;

    Thread human=new Thread(()->{
        while(true){
            if(!hasEggs){
                System.out.println("等待");
            }else{
                System.out.println("收取");
                hasEggs=false;
            }
        }
    });
    Thread hen=new Thread(()->{
        while(true){
            try{
                Thread.sleep(3000);
            }catch(InterruptedException e){
                e.printStackTrace();
            }
            hasEggs=true;
        }
    });

    public static void main(String[] args) {
        EggTest eggTest=new EggTest();
        eggTest.hen.start();
        eggTest.human.start();
    }
}
